using System.Collections;
using System.Collections.Generic;
using EventUtils;
using UnityEngine;
using UnityEngine.UI;
using EventType = EventUtils.EventType;

namespace View.Instant
{
    public class ReviveView : View
    {
        private Button mbtnClose;
        private Button mbtnSee;
        
        public override void OnLoad()
        {
            base.OnLoad();

            mbtnClose = transform.Find("btnClose").GetComponent<Button>();
            mbtnSee = transform.Find("btnSee").GetComponent<Button>();
            
            AddClickListener(mbtnClose,() =>
            {
                MJCtrl.Instance().OnDesctroyCard();
                UIManager.Instance.Close(ViewName.ReviveView);
                UIManager.Instance.Show(ViewName.GameEndView,ViewLayer.Game, 0);
            });
            
            AddClickListener(mbtnSee,() =>
            {
                UIManager.Instance.OnShowLoading();
                AndroidManager.Ins.LoadReward(() =>
                {
                    UIManager.Instance.OnCloseLoading();
                    TaskManager.OnAddTaskNumByTaskType(TaskTypeEnum.adv);
                    EventCenter.BroadCast<string>(EventType.EVENT_SEE_ADV_END,ViewName.ReviveView);
                });
            });
        }

        private void OnSeeAdvEnd(string str)
        {
            if ((ViewName.ReviveView) == str)
            {
                UIManager.Instance.Close(ViewName.ReviveView);
                GameHelp.G1GameEndSeeAdv++;
                GameHelp.CanRayCast = true;
                Debug.LogError("看完回来");
                EventCenter.BroadCast<int>(EventUtils.EventType.EVENT_LOGIN_INIT_LOAD_MJRES,3);
            }
        }
        public override void OnShow(params object[] args)
        {
            base.OnShow();
            EventCenter.AddListener<string>(EventUtils.EventType.EVENT_SEE_ADV_END,OnSeeAdvEnd);
        }

        public override void OnClose(params object[] args)
        {
            base.OnClose();
            if (gameObject.activeSelf)
            {
                EventCenter.RemoveListener<string>(EventUtils.EventType.EVENT_SEE_ADV_END,OnSeeAdvEnd);
            }
        }
    }
}
